<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button id="btn">点击了</button>
    <script>
        function fangdou(fn,awat,bl){  //防抖  函数
            if( typeof  fn!=='function') return
            if(awat=='undefined') awat=500
            if( typeof bl!=='boolean') bl=false
            let tiem=null;
            let one=false
            return function(...args){
                clearTimeout(tiem)
                tiem=setTimeout(()=>{
                    if(!bl) fn.apply(this,args)
                },awat)
                if(bl &&!one) {
                    one=true
                    fn.apply(this,args)
                }
            }
        }

        function btns(e){
            console.log('提交了1',e.target);
            // e.target
        }
        btn=document.getElementById('btn');
        // btn.onclick=fangdou(btns,500,true)
        btn.onclick=fangdou(btns,500,false)




        // 节流函数
        function scrollFUN(fn,awai){
            let prs=0;
            return function(){
                let now=new Date();//当前的时间
                let ins=awai-(now-prs) //时间的差
                if(ins<=0){
                    fn()
                    prs=new Date()
                }else{
                    // console.log(ins+'=====')
                    // let time=setTimeout(()=>{
                    //     clearTimeout(time)
                    //     fn()
                    //     prs=new Date()
                    // },ins)
                }
                // console.log(ins)
            }
        }
        function scroll(){
            console.log('滚动了')
        }
        window.onscroll=scrollFUN(scroll,1000)
        document.body.style.height=10000+'px'
    </script>
</body>
</html>